package com.wenzhiguo.myheadline.fragment;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.wenzhiguo.myheadline.R;
import com.wenzhiguo.myheadline.fragment.Login.Login_DengLu;

/**
 * A simple {@link Fragment} subclass.
 */
public class LoginFragment extends Fragment implements View.OnClickListener {

    private String[] name = new String[]{"消息通知", "活动", "头条商城", "京东特供  新人领188元红包", "我要爆料", "用户反馈"};
    private View view;
    private ListView lv;
    private ImageView arrow;
    private ImageView phone;

    public LoginFragment() {
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_login, container, false);
        initView();
        return view;
    }

    private void initView() {
        //控件list
        lv = (ListView) view.findViewById(R.id.Login_lv);
        lv.setAdapter(new MyAdapter());
        //图片控件
        arrow = (ImageView) view.findViewById(R.id.Voide_picture_jiantou);
        phone = (ImageView) view.findViewById(R.id.Voide_picture_shouji);
        //监听
        arrow.setOnClickListener(this);
        phone.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        switch (id) {
            case R.id.Voide_picture_jiantou:
                Jump(new Login_DengLu());
                break;
            case R.id.Voide_picture_shouji:
                Jump(new Login_DengLu());
                break;
        }
    }

    private void Jump(Activity a) {
        Intent intent = new Intent(getActivity(), a.getClass());
        startActivity(intent);
    }

    class MyAdapter extends BaseAdapter {
        @Override
        public int getCount() {
            return name.length;
        }

        @Override
        public Object getItem(int position) {
            return name[position];
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder holder;
            if (convertView == null) {
                holder = new ViewHolder();
                convertView = View.inflate(getActivity(), R.layout.login_listview, null);
                holder.login_name = (TextView) convertView.findViewById(R.id.login_text);
                convertView.setTag(holder);
            } else {
                holder = (ViewHolder) convertView.getTag();
            }
            holder.login_name.setText(name[position]);
            return convertView;
        }

        class ViewHolder {
            TextView login_name;
        }
    }
}
